﻿/* ==============================================================================
 * Copyright (c) ShangXichao All right reserved. 
 * 类名称：VZeroIsSetConverter
 * 类描述：
 * 创建人：SXC
 * 创建时间：2014/4/27 20:50:12
 * 修改人：
 * 修改时间：
 * 修改备注：
 * @version 1.0
 * ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace KZ400B.Controls.Converters
{
    public class VZeroIsSetConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                bool isSet = (bool)value;
                if (isSet)
                {
                    return System.Windows.Visibility.Visible;
                }
                return System.Windows.Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                Console.WriteLine("VZeroIsSetConverter Error:{0}",ex.Message);
            }
            return System.Windows.Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                System.Windows.Visibility vb = (System.Windows.Visibility)value;
                switch (vb)
                { 
                    case System.Windows.Visibility.Collapsed:
                    case System.Windows.Visibility.Hidden:
                        return false;
                    case System.Windows.Visibility.Visible:
                        return true;
                    default: return false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("VZeroIsSetConverter ConvertBack Error:{0}", ex.Message);
            }
            return false;
        }
    }

    public class VZeroIsSetInfoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                bool isSet = (bool)value;
                if (isSet)
                {
                    return "已设置";
                }
                return "未设置";
            }
            catch (Exception ex)
            {
                Console.WriteLine("VZeroIsSetInfoConverter Error:{0}", ex.Message);
            }
            return "未设置";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                string vb = value.ToString();
                if (vb == "未设置")
                {
                    return false;
                }
                else if (vb == "已设置")
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("VZeroIsSetInfoConverter ConvertBack Error:{0}", ex.Message);
            }
            return false;
        }
    }
}
